<?php
namespace Home\Controller;
header("Access-Control-Allow-Origin: *");
class MockdataController extends CommonController 
{
	// 查询自媒体列表
	public function getlist()
	{
		$Classmedia = D('Classmedia');
		$data = $Classmedia->GetMockDataList();
		$this->ApiSuccess('ok',$data);
	}

	// 查询自媒体详情
	public function getmediainfo()
	{
		$Classmedia = D('Classmedia');
		$data = $Classmedia->GetMediafind($_GET['id']);
		$this->ApiSuccess('ok',$data);
	}

	// 查询自媒体对应音频列表
	public function getmediamusicinfo()
	{
		$Classmedia = D('Classmedia');
		$data = $Classmedia->GetMockAudioList($_GET['id']);
		foreach ($data as $k => $v) {
			$data[$k]['number'] = '00' . ($k + 1);
			if(strlen($data[$k]['number']) > 3){
				$data[$k]['number'] = substr($data[$k]['number'],1);
			}
		}
		$data = array_reverse($data);
		$r['page_sum'] = count($data);
		$r['total_page'] = 1;
		$r['data'] = $data;
		$this->ApiSuccess('ok',$r);
	}

	// 查询对应did的音频信息
	public function getdidimusic(){
		$did = I('get.did');
		$data = M('zsmedia')->where("id=".$did)->find();
		$data['wz'] = htmlspecialchars_decode($data['wz']);  
		$data['time'] = (int)json_decode(do_curl($data['url2'].'?avinfo'),true)['format']['duration'];
		$data['time'] = date("i:s",$data['time']);
		if(!empty($data)){
			$this->ApiSuccess('ok',$data);
		}else{
			$this->ApiError('请求异常','999999');
		}		
	}
}